package top.manbutech.activity.activitydemo;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private EditText mUsername;
    private EditText mPassword;
    private Button mLogin;
    private Button mCall;
    private Button mSendEms;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();

        initListener();

    }

    private void initListener() {
        mLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //登录按钮点击
                handlerLogin();
            }
        });

        mCall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                handlerCall();
            }
        });

        mSendEms.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                
            }
        });


    }

    private void handlerCall() {
        Intent call = new Intent();
        call.setAction("android.intent.action.CALL");
        call.addCategory("android.intent.category.DEFAULT");
        Uri uri = Uri.parse("tel:10086");
        call.setData(uri);
        startActivity(call);
    }

    private void handlerLogin() {
        String username = mUsername.getText().toString().trim();
        if (TextUtils.isEmpty(username)) {
            Toast.makeText(this,"用户名不能为空",Toast.LENGTH_SHORT).show();
            return;
        }

        String password = mPassword.getText().toString().trim();
        if (TextUtils.isEmpty(password)) {
            Toast.makeText(this,"密码不能为空",Toast.LENGTH_SHORT).show();
            return;
        }

        //显示意图
        //Intent intent = new Intent(this,SecondActivity.class);
        //intent.putExtra("username",username);
        //intent.putExtra("password",password);
        //startActivity(intent);

        Intent intent = new Intent();
        intent.setAction("top.manbutech.LOGIN_INFO");
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.putExtra("username",username);
        intent.putExtra("password",password);
        startActivity(intent);


    }

    private void initView() {
        mUsername = (EditText) this.findViewById(R.id.username);
        mPassword = (EditText) this.findViewById(R.id.password);
        mLogin = (Button) this.findViewById(R.id.login);

        mCall = (Button) this.findViewById(R.id.call);
        mSendEms = (Button) this.findViewById(R.id.sendEms);
    }

}
